#docker build -t supermatrix_client -f docker/CameraNode/Dockerfile 
FROM debian:trixie
RUN apt update -y && apt install -y cmake gcc g++ unzip make libasio-dev pkg-config curl libspdlog-dev libfmt-dev libboost-dev nlohmann-json3-dev libthrift-dev xz-utils thrift-compiler && apt clean 
RUN curl -o oatpp.zip -L https://github.com/oatpp/oatpp/archive/refs/heads/master.zip
RUN unzip oatpp.zip && cd oatpp-master && mkdir build && cd build && cmake -DOATPP_BUILD_TESTS=OFF .. && make -j$(nproc) && make install &&  cd / && rm oatpp.zip && rm -r oatpp-master
RUN curl -o oatpp-websocket.zip -L https://github.com/oatpp/oatpp-websocket/archive/refs/heads/master.zip 
RUN unzip oatpp-websocket.zip && cd oatpp-websocket-master && mkdir build && cd build && cmake -DOATPP_BUILD_TESTS=OFF .. && make -j$(nproc) && make install && cd / && rm oatpp-websocket.zip && rm -r oatpp-websocket-master
RUN curl -o mqtt5.zip -L https://github.com/mireo/async-mqtt5/archive/refs/heads/master.zip 
RUN unzip mqtt5.zip && cd async-mqtt5-master && mkdir build && cd build && cmake .. && make -j$(nproc) && make install && cd / && rm mqtt5.zip && rm -r async-mqtt5-master
COPY . /SuperMatrix
RUN cd SuperMatrix && mkdir build && cd build && cmake .. -DBUILD_TARGET_DEVICE="Client" -DCMAKE_BUILD_TYPE="Release" -DDISABLE_TEST="On" && make -j${nproc} && make install && cd / && rm -r SuperMatrix && ldconfig

RUN mkdir s6-overlay
ARG S6_OVERLAY_VERSION=3.1.6.2
RUN curl -o /s6-overlay/s6-overlay-noarch.tar.xz -L https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-noarch.tar.xz  
RUN curl -o /s6-overlay/s6-overlay-aarch64.tar.xz -L https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-aarch64.tar.xz  

RUN apt remove -y cmake gcc g++ unzip make curl pkg-config xz-utils thrift-compiler && apt autoremove -y

FROM busybox:glibc
COPY --from=0 /usr/local/bin /usr/local/bin
COPY --from=0 /usr/lib/aarch64-linux-gnu /lib
COPY --from=0 /usr/local/lib /lib
COPY --from=0 /s6-overlay/s6-overlay-noarch.tar.xz /tmp/
COPY --from=0 /s6-overlay/s6-overlay-aarch64.tar.xz /tmp/
COPY --from=0 /usr/bin/bash /bin/
COPY docker/CameraNode/s6 /etc/s6-overlay/s6-rc.d
COPY docker/CameraNode/s6-start /etc/s6-overlay/s6-rc.d/user/contents.d

RUN mkdir /etc/supermatrix
RUN tar -C / -Jxpf /tmp/s6-overlay-noarch.tar.xz
RUN tar -C / -Jxpf /tmp/s6-overlay-aarch64.tar.xz
ENTRYPOINT ["/init"]
